"use strict";
cc._RF.push(module, 'c5541O5JJtECJxoddvypT7p', 'main_role_view_ui');
// scripts/main_role_view_ui.js

"use strict";

var e = require;
var t = module;
var o = exports;

var _ii,
    nn = void 0 && (void 0).__extends || (_ii = function ii(t, e) {
  return (_ii = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _ii(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    rr = void 0 && (void 0).__awaiter || function (t, e, o, i) {
  return new (o || (o = Promise))(function (n, a) {
    function r(t) {
      try {
        l(i.next(t));
      } catch (e) {
        a(e);
      }
    }

    function s(t) {
      try {
        l(i["throw"](t));
      } catch (e) {
        a(e);
      }
    }

    function l(t) {
      var e;
      t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
        t(e);
      })).then(r, s);
    }

    l((i = i.apply(t, e || [])).next());
  });
};

var oo = void 0 && (void 0).__decorate || function (e, t, a, n) {
  var i,
      o = arguments.length,
      s = o < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, a) : n;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);else for (var r = e.length - 1; r >= 0; r--) {
    (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
  }
  return o > 3 && s && Object.defineProperty(t, a, s), s;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var a = e("BaseModuleUI"),
    n = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("CommonHelper"),
    s = e("PureHelper"),
    l = e("nameCfg"),
    _ = e("RoleSoldierInfo"),
    c = e("sdkConfig"),
    d = cc._decorator,
    h = d.ccclass,
    u = d.property,
    p = function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    return t.my_role_ske = null, t.level_name_label = null, t.ai_view_ui = null, t.ai_role_item = null, t.ai_num = 0, t.ai_name_list = [], t.my_hero_node = null, t;
  }

  return nn(t, e), t.prototype.initView = function () {
    e.prototype.initView.call(this), this.showPlayerInfo(), this.showMainRoleInfo(), this.getAiInfo();
  }, t.prototype.addEvent = function () {
    this.attachEvent(n["default"].SEND_UPDATE_MY_USE_HORE_INFO, this.showMainRoleInfo, this), this.attachEvent(n["default"].SEND_UPDATE_PLAYER_INFO, this.showPlayerInfo, this);
  }, t.prototype.showPlayerInfo = function () {
    var e = i.GlobalParams.PlayerInfo.value;
    this.level_name_label.string = "Lv." + e.level + "  " + e.name;
  }, t.prototype.showMainRoleInfo = function () {
    var e = this,
        t = i.GlobalParams.playerSkinInfo.value,
        o = _["default"].Role_info[t.use[0]];
    this.my_hero_node = this.my_role_ske.node.parent, this.my_hero_node.active = !0, this.uiManager.getRoleSkele(o.id, function (t) {
      e.my_role_ske.skeletonData = t, e.my_role_ske.setAnimation(0, "battle_idle", !0), e.my_role_ske.node.parent.setParent(e.ai_view_ui);
    });
  }, t.prototype.getAiInfo = function () {
    var e = i.GlobalParams.PlayerInfo.value;
    this.ai_num = r["default"].getRandomInt(8, 12), this.ai_name_list = [], this.ai_name_list.push(e.name);

    for (var t = 0; t < this.ai_num; t++) {
      var o = "";

      do {
        o = c["default"].platform != c.EPlatform.NET_4399 ? l["default"].nameList[r["default"].getRandomInt(0, l["default"].nameList.length - 1)] : "4399玩家" + r["default"].getRandomInt(1e3, 9999);
      } while (-1 != this.ai_name_list.indexOf(o));

      this.ai_name_list.push(o);
    }

    this.showAiViewInfo();
  }, t.prototype.showAiViewInfo = function () {
    for (var e = i.GlobalParams.PlayerInfo.value, t = function t(_t) {
      var a = cc.instantiate(o.ai_role_item),
          n = r["default"].getRandomInt(1, 15),
          i = a.children[0].getComponent(sp.Skeleton);
      o.uiManager.getRoleSkele(n, function (e) {
        i.skeletonData = e, i.setAnimation(0, "battle_idle", !0), a.active = !0;
      });
      var s = e.level + r["default"].getRandomInt(-5, 5);
      a.children[1].getComponent(cc.Label).string = "Lv." + (s < 1 ? 1 : s) + "  " + o.ai_name_list[_t];
      var l = cc.v2(r["default"].getRandomInt(-1100, 1100), r["default"].getRandomInt(-380, 130));
      a.setPosition(l), a.setParent(o.ai_view_ui);
    }, o = this, a = 0; a < this.ai_num; a++) {
      t(a);
    }
  }, t.prototype.update = function () {
    var e = this.ai_view_ui.children;
    e.sort(function (e, t) {
      return t.y - e.y;
    });

    for (var t = 0; t < e.length; t++) {
      e[t].zIndex = t, e[t].opacity = this.myDisRound() ? 255 : 0;
    }
  }, t.prototype.myDisRound = function () {
    var e = !1;
    return Math.abs(s["default"].Distance(this.node.getPosition(), this.my_hero_node.getPosition())) < i.GlobalParams.showMaxDis && (e = !0), e;
  }, oo([u(sp.Skeleton)], t.prototype, "my_role_ske", void 0), oo([u(cc.Label)], t.prototype, "level_name_label", void 0), oo([u(cc.Node)], t.prototype, "ai_view_ui", void 0), oo([u(cc.Node)], t.prototype, "ai_role_item", void 0), oo([h], t);
}(a["default"]);

o["default"] = p;

cc._RF.pop();